import {Component, EventEmitter, OnInit, Output, Input, OnChanges, SimpleChanges} from '@angular/core';
import {GetRTDataByKKSCodesService} from '../../../services/get-rtdata-by-kkscodes.service'

@Component({
  selector: 'app-modal-device-blade',
  templateUrl: './modal-device-blade.component.html',
  styleUrls: ['./modal-device-blade.component.css']
})
export class ModalDeviceBladeComponent implements OnInit,OnChanges {
  ngOnChanges(changes: SimpleChanges): void {
    if(changes['kkscode']&&this.kkscode){
      this.getData(this.kkscode,this.time);
    }
  }

  constructor(
    private getBladeData:GetRTDataByKKSCodesService
  ) { }

  @Output() hideModal= new EventEmitter<any>()

  @Input() kkscode:string
  @Input() time:number

  public compareLineOption:object
  public residualLineOption:object

  ngOnInit() {
  }

  getData(kkscode:string,time:number){
    //...获取数据
    this.getBladeData.getBlade(kkscode,time)
      .subscribe(data=>{
        this.fillChart(data.selfCurveList,data.standardCurveList,data.errList,data.errAvg)
      })
    // let line1=[],line2=[],line3=[]
    // for(let i=-1000,N=1000;i<N;i++){
    //   line1.push([i/10,Math.cos(i/10)])
    //   line2.push([i/10,Math.sin(i/10)])
    //   line3.push([i/10,Math.tan(i/10)])
    // }
    // this.fillChart(line1,line2,line3,0.3);
  }

  fillChart(observeLine:Array<number>,
            estimateLine:Array<number>,
            residualLine:Array<number>,point?:number){
    this.compareLineOption={
      chart:{
        spacing:[10,10,10,5],
        borderRadius:5
      },
      title: {
        text: '风机观测值与估计值对比曲线',
        style:{
          "color": "#333333",
          "fontSize": "14px"
        }
      },
      subtitle: {
      },
      xAxis: {
      },
      yAxis: {
        title: {
          text: '桨距角'
        },
      },
      tooltip: {
        // valueSuffix: '°C'
      },
      credits:{
        enabled:false
      },
      legend: {
        align: 'right',
        verticalAlign: 'top',
        x: -10,
        y: 50,
        floating: true
      },
      series: [{
        name: '观测值',
        data: observeLine
      }, {
        name: '估计值',
        data: estimateLine
      }]
    }
    this.residualLineOption={
      chart:{
        spacing:[10,10,10,5],
        borderRadius:5
      },
      title: {
        text: '风机残差曲线',
        style:{
          "color": "#333333",
          "fontSize": "14px"
        }
      },
      subtitle: {
        text:'变桨角度低于全场平均'+(point?point.toFixed(2):'')+'°',
        style:{
          "color": "#333333",
          "fontSize": "12px"
        },
        y:28
      },
      xAxis: {
      },
      yAxis: {
        title: {
          text: '残差'
        },
      },
      tooltip: {
        // valueSuffix: '°C'
      },
      credits:{
        enabled:false
      },
      legend: {
        align: 'right',
        verticalAlign: 'top',
        x: -10,
        y: 50,
        floating: true
      },
      series: [{
        name: '残差',
        data: residualLine
      }]
    }
  }

  hideChildModal(){
    this.hideModal.emit()
  }

}
